/**
 * @param {number[]} temperatures
 * @return {number[]}
 */
// 找到第一个当前元素大的值，单调栈，从栈顶往栈底递增
var dailyTemperatures = function (temperatures) {
    let stack = [], res = [], len = temperatures.length, l1 = 0;
    for (let i = 0; i < len; i++) {
        while (stack.length !== 0 && stack[stack.length - 1] < temperatures[i]) {
            stack.pop()
            let l2 = stack.length;
            res[l1 + l2] = i - l1 - l2;
            l1++;
        }
        stack.push(temperatures[i])
    }
    while (stack.length !== 0) {
        stack.pop()
        let l2 = stack.length;
        res[l1 + l2] = 0;
        l1++;
    }
    return res;
};
console.log(dailyTemperatures([73, 74, 75, 71, 69, 72, 76, 73]));
console.log(dailyTemperatures([30, 40, 50, 60]));